package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhOrder;
import com.ruoyi.edh.domain.dto.EdhOrderListDto;
import com.ruoyi.edh.domain.model.OrdersStatisticModel;
import com.ruoyi.edh.domain.vo.*;
import com.ruoyi.edh.service.IEdhOrderService;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订购-订单Controller
 *
 * @author xxx
 * @date 2020-09-03
 */
@RestController
@RequestMapping("/edh/order")
@Api(description = "易订购-订单")
public class EdhOrderController extends BaseController {
    @Autowired
    private IEdhOrderService edhOrderService;

    /**
     * 查询易订购-订单列表
     */
    @GetMapping("/list")
    @ApiOperation("易订购-订单列表")
    public TableDataInfo list(EdhOrderListDto edhOrder) {
        startPage();
        List<EdhSummaryOrderListVo> list = edhOrderService.selectEdhOrderList(edhOrder);
        return getDataTable(list);
    }


    /**
     * 导出易订购-订单列表
     */
    @Log(title = "易订购-订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订购-订单列表")
    public AjaxResult export(EdhOrderListDto edhOrder) {
        List<EdhSummaryOrderExcleListVo> list = edhOrderService.selectEdhOrderExcelList(edhOrder);
        ExcelUtil<EdhSummaryOrderExcleListVo> util = new ExcelUtil<EdhSummaryOrderExcleListVo>(EdhSummaryOrderExcleListVo.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取易订购-订单详细信息
     */
    @GetMapping
    @ApiOperation("获取易订购-订单详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhOrderService.selectEdhOrderById(id));
    }

    /**
     * 新增易订购-订单
     */
    @Log(title = "易订购-订单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订购-订单")
    public AjaxResult add(@RequestBody EdhOrder edhOrder) {
        return toAjax(edhOrderService.insertEdhOrder(edhOrder));
    }

    /**
     * 修改易订购-订单
     */
    @Log(title = "易订购-订单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订购-订单")
    public AjaxResult edit(@RequestBody EdhOrder edhOrder) {
        return toAjax(edhOrderService.updateEdhOrder(edhOrder));
    }

    /**
     * 取消售后接口
     */
    @ApiOperation("取消售后接口")
    @GetMapping("/cancelAftermarket")
    public AjaxResult cancelAftermarket(Long orderId) {
        return toAjax(edhOrderService.cancelAftermarket(orderId));
    }

    /**
     * 删除易订购-订单
     */
    @Log(title = "易订购-订单", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订购-订单")
    public AjaxResult remove(String ids) {
        return toAjax(edhOrderService.deleteEdhOrderByIds(ids.split(",")));
    }

    /**
     * 查询我的订单
     *
     * @param orderStatus
     * @return
     */
    @GetMapping("/selectEdhMyOrder")
    @ApiOperation("易订购-查询我的订单")
    public TableDataInfo selectEdhMyOrder(@RequestParam(value = "orderStatus", required = false) String orderStatus,
                                          @RequestParam(value = "returnStatus", required = false) String returnStatus) {
        startPage();
        List<EdhMyOrderVo> edhMyOrderVos = edhOrderService.selectEdhMyOrder(orderStatus, returnStatus);
        return getDataTable(edhMyOrderVos);
    }

    /**
     * 查询易订购-订单列表
     */
    @GetMapping("/microshopOrderList")
    @ApiOperation("易订购-微店订单订单列表")
    public TableDataInfo microshopList(EdhOrderListDto edhOrder) {
        startPage();
        List<EdhMyOrderVo> list = edhOrderService.selectMicroshopList(edhOrder);
        return getDataTable(list);
    }

    /**
     * 查询订单详情
     *
     * @param id
     * @return AjaxResult
     */
    @GetMapping("/selectDetailsOrder")
    @ApiOperation("易订购-查询订单详情")
    @ApiParam(name = "id", value = "订单id")
    public AjaxResult selectDetailsOrder(@RequestParam("id") String id) {
        EdhDetailsOrderVo edhDetailsOrderVo = edhOrderService.selectDetailsOrder(id);
        return edhDetailsOrderVo != null ? AjaxResult.success("查询成功", edhDetailsOrderVo) : AjaxResult.error("查询失败");
    }

    /**
     * 获取订单销售情况
     */
    @GetMapping("/getOrderFulfillment")
    @ApiOperation("获取订单销售情况")
    public AjaxResult getOrderFulfillment() {
        return AjaxResult.success(edhOrderService.getOrderFulfillment());
    }

    /**
     * 首页待处理事务数据
     */
    @GetMapping("/pendingTransaction")
    @ApiOperation("首页待处理事务数据")
    public AjaxResult pendingTransaction() {
        return AjaxResult.success(edhOrderService.pendingTransaction());
    }

    /**
     * 首页订单总数统计图数据
     */
    @PostMapping("/totalOrdersStatistics")
    @ApiOperation("首页订单总数统计图数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型 1今日 2本周 3本月 4自定义时间查询 默认本周"),
            @ApiImplicitParam(name = "time", value = "查询时间(只有type=4的时候传)")
    })
    public AjaxResult totalOrdersStatistics(@RequestBody OrdersStatisticModel model) {
        return AjaxResult.success(edhOrderService.totalOrdersStatistics(model.getType(), model.getTime()));
    }

    /**
     * 首页订单销售额统计图数据
     */
    @PostMapping("/orderSalesStatistics")
    @ApiOperation("首页订单销售额统计图数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型 1今日 2本周 3本月 4自定义时间查询 默认本周"),
            @ApiImplicitParam(name = "time", value = "查询时间(只有type=4的时候传)")
    })
    public AjaxResult orderSalesStatistics(@RequestBody OrdersStatisticModel model) {
        return AjaxResult.success(edhOrderService.orderSalesStatistics(model.getType(), model.getTime()));
    }

    /**
     * 首页订单总数对比数据
     */
    @GetMapping("/totalOrderComparison")
    @ApiOperation("首页订单总数对比数据")
    public AjaxResult totalOrderComparison() {
        return AjaxResult.success(edhOrderService.totalOrderComparison());
    }

    /**
     * 首页订单销售额对比数据
     */
    @GetMapping("/totalOrderSalesComparison")
    @ApiOperation("首页订单销售额对比数据")
    public AjaxResult totalOrderSalesComparison() {
        return AjaxResult.success(edhOrderService.totalOrderSalesComparison());
    }

    @PutMapping("/batchShip")
    @ApiOperation("批量发货")
    public AjaxResult batchShip(@RequestBody List<EdhOrder> edhBatchShip) {
        return toAjax(edhOrderService.batchShip(edhBatchShip));
    }

    /**
     * @param id
     * @description: 根据id查询订单详情
     * @return: EdhOrderDetailsVo
     * @author: 梁东宸
     * @time: 2020/9/15 8:37 下午
     */
    @GetMapping("/OrderDetailsById")
    @ApiOperation("根据id查询订单详细")
    public AjaxResult selectOrderDetailsById(@RequestParam("id") String id) {
        EdhOrderDetailsVo edhOrderDetailsVo = edhOrderService.selectOrderDetailsById(id);
        return null != edhOrderDetailsVo ? AjaxResult.success("查询成功", edhOrderDetailsVo) : AjaxResult.error("查询失败");
    }

    /**
     * @param id,remarks 订单id和操作备注
     * @description: 添加操作记录
     * @return:
     * @author: 梁东宸
     * @time: 2020/9/16 4:01 下午
     */
    @GetMapping("/addOrderLog")
    @ApiOperation("添加订单操作记录接口")
    public AjaxResult addOrderLog(@RequestParam("id") Long id, @RequestParam("remarks") String remarks, @Param("type") String type) {
        return toAjax(edhOrderService.addOrderLog(id, remarks, type));
    }

    ;

    /**
     * @param edhOrder
     * @description: 查询待打印订单
     * @return: TableDataInfo
     * @author: 梁东宸
     * @time: 2020/9/17 9:51 上午
     */
    @GetMapping("/selectNotShipOrder")
    @ApiOperation("查询待打印订单列表")
    public TableDataInfo selectNotShipOrder(EdhOrder edhOrder) {
        startPage();
        List<EdhOrderDetailsVo> edhOrderDetailsVos = edhOrderService.selectNotShipOrder(edhOrder);
        return getDataTable(edhOrderDetailsVos);
    }


}
